package app;/**
 * @description:
 * @authoer: Max Woods
 * @create:2018/7/3 18:13
 **/


import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.util.FalsifyingWebConnection;

import java.io.IOException;

/**
 *@auther: Max Woods
 *@create:2018/7/3 18:13
 **/
public class InterceptWebConnection extends FalsifyingWebConnection {

    public InterceptWebConnection(WebClient webClient) throws IllegalArgumentException{
        super(webClient);
    }

    @Override
    public WebResponse getResponse(WebRequest request) throws IOException {
        WebResponse response=super.getResponse(request);
        String js=response.getWebRequest().getUrl().toString();
        if(js.endsWith("16312937.js")||(js.contains("index.php?m=poster&c=index&a=show_poster"))){
            return createWebResponse(response.getWebRequest(), "", "application/javascript", 200, "Ok");
        }
        return super.getResponse(request);
    }
}
